from math import sin, cos, pi

MCver: float = 1.16  # or 1.17
verCase: int = 60009 if MCver == 1.16 else 60011
mul = 25214903917
mask = (1 << 48) - 1
unit = 1 << 53
leather_Arm = [1, 3, 2, 1]  # 7
gold_Arm = [2, 5, 3, 1]  # 11
Chainmail_Arm = [2, 5, 4, 1]  # 12
iron_Arm = [2, 6, 5, 2]  # 15
diamond_Arm = [3, 8, 6, 3]  # 20
scute_Arm = [2, 0, 0, 0]
diamond_Tou = [2, 2, 2, 2]  # 8
nether_Tou = [3, 3, 3, 3]  # 12
leather_House = [3, 0, 0, 0]
gold_House = [5, 0, 0, 0]
iron_House = [7, 0, 0, 0]
diamond_House = [11, 0, 0, 0]


def finDiamond(seed: int, x: int, z: int) -> "tuple[int]":
    """计算seed世界区块(x，z)的钻石生成"""
    temp = [seed ^ mul & mask]
    temp.extend((temp[-1] * mul + 11) & mask for _ in range(4))
    temp2 = [i >> 16 << 32 if i % 2 else i << 16 >> 32 for i in temp[1:]]
    i, j = sum(temp2[:2]) | 1, sum(temp2[2:]) | 1
    t3 = (16 * (x * i + z * j) ^ seed + verCase) ^ mul & mask
    x1 = (t3 * mul + 11) & mask
    z1 = (x1 * mul + 11) & mask
    x1, z1 = x1 >> 44, z1 >> 44
    return 16 * x + x1, 16 * z + z1


def findFortress(seed: int) -> "tuple[int]":
    """根据地图种子找到要塞x,z坐标，适用于1.9-1.18"""
    temp = [seed ^ mul & mask]
    temp.extend((temp[-1] * mul + 11) & mask for _ in range(4))
    theta = ((temp[1] >> 22 << 27) + (temp[2] >> 21)) / unit * 2 * pi
    r = ((temp[3] >> 22 << 27) + (temp[4] >> 21)) / unit * 80 + 88
    print(theta, r)
    return round(r * cos(theta)) * 16, round(r * sin(theta)) * 16


class damage_calc:
    """伤害计算器"""

    def __init__(self) -> None:
        self.Armor = [0, 0, 0, 0]
        self.Toughness = [0, 0, 0, 0]
        self.Resistance = 0

    def setArmor(self, Armor: list):
        """设置护甲值"""
        self.Armor = Armor
        return self

    def setToughness(self, Toughness: list):
        """设置护甲韧性"""
        self.Toughness = Toughness
        return self

    def setResistance(self, Resistance: int):
        """设置抗性提升Buff"""
        self.Resistance = Resistance
        return self

    def __call__(self, damage: float) -> float:
        tough = 1 / (2 + sum(self.Toughness) / 4)
        res = max(sum(self.Armor) / 5, sum(self.Armor) - damage * tough)
        res = min(res, 20) / 25
        return damage * (1 - res) * (1 - 0.2 * self.Resistance)


if __name__ == "__main__":
    print(finDiamond(123, 3, 5))
    print(findFortress(123))
